<template>
	<div class="page-header" shadow="never"><span>用户列表</span></div>
	<div class="page-card">
		<el-table :data="state.userList" v-loading="loading">
			<el-table-column label="头像" width="100px" align="center">
				<template #default="scope">
					<el-avatar :size="35" :src="scope.row.avatar"></el-avatar>
				</template>
			</el-table-column>
			<el-table-column prop="username" label="昵称" />
			<el-table-column prop="gender" width="100px" label="性别" />
			<el-table-column width="100px" label="用户类型" align="center">
				<template #default="scope">
					{{userTypeDic[scope.row.type]}}
				</template>
			</el-table-column>
			<el-table-column :formatter="$utils.timeFormat" prop="last_login_time" label="最近登录" align="center" />
			<el-table-column :formatter="$utils.timeFormat" prop="create_time" label="创建时间" align="center" />
			<el-table-column width="100px" label="用户状态" align="center">
				<template #default="scope">
					<span style="color: #529b2e;">{{userStatusDic[scope.row.status]}}</span>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="200px" align="center">
				<template #default="scope">
					<el-button @click="onEdit(scope.row,scope.$index)" type="primary" text>编辑</el-button>
				</template>
			</el-table-column>
		</el-table>
		<QPagination :current-page="state.currentPage" :page-size="pageSize" :page-count="state.pageCount"
			:data-total="state.dataTotal" @current-change="pageChange"></QPagination>
	</div>
</template>
<script setup>
import { ElMessageBox } from 'element-plus';
import { onMounted, reactive, ref } from 'vue';
import http from '@/utils/request';
import QPagination from '../../components/q-pagination/q-pagination.vue';

let userTypeDic = {
	1: "微信小程序",
	9: "官方账号"
}

let userStatusDic = {
	0: "正常",
	1: "禁用"
}

const pageSize = ref(10);

let loading = ref(false)
let state = reactive({
	userList: [],
	pageCount: 0,
	currentPage: 1,
	dataTotal: 0,
	showSetSchoolDialog: false,
	schoolKeyword: '',
	selectSchoolId: null,
	selectUserInfo: null
})


onMounted(() => {
	getUserList()
})

//删除用户
function onEdit(e, index) {

}

//获取用户列表数据
function getUserList() {
	loading.value = true;
	http.get('/api/user/list', {
		page: state.currentPage
	}).then(res => {
		if (res.code == 200) {
			state.pageCount = res.result.last_page;
			state.dataTotal = res.result.total;
			state.userList = res.result.data;
		}

		loading.value = false;
	});
}

//页面改变时
function pageChange(page) {
	state.currentPage = page;
	getUserList();
}

</script>
<style>

</style>
